package com.haiya.identityaccess.controller;


import com.haiya.identityaccess.application.representation.TenantRepresentation;
import com.haiya.identityaccess.domain.DomainRegistry;
import com.haiya.identityaccess.domain.identity.model.Tenant;
import com.haiya.identityaccess.domain.identity.model.TenantId;
import com.haiya.identityaccess.domain.identity.repository.TenantRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qiaoguoqiang
 */
@RequestMapping("/api/tenant")
@RestController
public class TenantController {

    /**
     * 租户详情接口
     * 这里我们直接调用存储库查询结果
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public TenantRepresentation info(@PathVariable("id") String id) {
        // String id = "8B12BA19-7C2F-4ED1-BBC8-DDF238AE1E5F";
        TenantRepository tenantRepository =
                (TenantRepository) DomainRegistry.getBean(TenantRepository.class);
        Tenant tenant = tenantRepository.tenantOfId(new TenantId(id));
        return new TenantRepresentation(tenant);
    }
}